package com.guli.mall.serviceBase.globalException;

import com.guli.common.pojo.vo.StatusCodeEnum;
import com.guli.common.utils.R;
import lombok.Data;
import org.springframework.util.ObjectUtils;

/*
 * @Author 罗
 * @date 2020/9/12 - 6:47 下午
 */
@Data
public class MallException extends RuntimeException {

    private Integer code;

//    private StatusCodeEnum statusCodeEnum;

    public MallException(StatusCodeEnum statusCodeEnum) {
        super(statusCodeEnum.getMsg());
        this.code = statusCodeEnum.getCode();

//        this.statusCodeEnum = statusCodeEnum;
    }

    public MallException() {
    }

    public MallException(StatusCodeEnum statusCodeEnum, String error) {
        super(statusCodeEnum.getMsg());
        this.code = statusCodeEnum.getCode();

        statusCodeEnum.setMsg(error);  //TODO 尚未完善

//        this.statusCodeEnum = statusCodeEnum;
    }

    public MallException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public MallException(String message) {
        super(message);
    }

    public MallException(Integer code) {
        this.code = code;
    }



    public MallException(R r) {

        super(r.getMsg());

        /*if (ObjectUtils.isEmpty(r.getCode())) {
            this.statusCodeEnum = StatusCodeEnum.STATUS_CODE_DOES_NOT_EXIST;
        }*/

        this.code = r.getCode();
    }
}
